import 'package:car_baidu/core/constant/initialize_data.dart';
import 'package:car_baidu/ui/shared/theme/app_theme.dart';
import 'package:flutter/material.dart';

import 'main_items.dart';

class LLMainScreen extends StatefulWidget {
  static const String routeName = "main";
  const LLMainScreen({Key? key}) : super(key: key);
  @override
  _LLMainScreenState createState() => _LLMainScreenState();
}

class _LLMainScreenState extends State<LLMainScreen> {
  bool _isFirstUseApplication = LLInitializeData.isFirstLogin;
  int _currentIndex = 0;
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Container(
        color: Colors.red,
        child: getMainContentWidget(context),
      ),
      bottomNavigationBar: _isFirstUseApplication
          ? null
          : BottomNavigationBar(
              type: BottomNavigationBarType.fixed,
              unselectedFontSize: LLAppTheme.normalTextStyle.fontSize!,
              selectedFontSize: LLAppTheme.normalTextStyle.fontSize!,
              unselectedItemColor: Colors.grey,
              selectedItemColor: LLAppTheme.primaryColor,
              items: bottomItems,
              currentIndex: _currentIndex,
              onTap: (index) {
                setState(() {
                  _currentIndex = index;
                });
              },
            ),
    );
  }

  Widget getMainContentWidget(BuildContext context) {
    // 判断是否是首次登陆. 从配置项获取
    if (_isFirstUseApplication) {
      return Container(
        alignment: Alignment(1, 1),
        color: Colors.red,
        child: TextButton(
          child: Text(
            "点击进入",
          ),
          onPressed: () {
            setState(() {
              LLInitializeData.comeApp();
              _isFirstUseApplication = false;
            });
          },
        ),
      );
    } else {
      return IndexedStack(
        index: _currentIndex,
        children: pages,
      );
    }
  }
}
